package com.situ.javase.day3;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {

//	1
//	12
//	123
//	1234
//	12345
	@Test
	public void test1() {
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(j);
			}
			System.out.println();
		}
	}
	
//	   *
//    ***
//   *****
//  *******
// *********
//***********
	// i=1    5		 1
	// i=2    4		 3
	// i=3    3		 5
	// i=4    2		 7
	//        (6-i)       (2i-1)
	@Test
	public void test2() {
		for (int i = 1; i <= 6; i++) {
			for (int j = 1; j <= (6 - i); j++) {
				System.out.print("-");
			}
			for (int j = 1; j <= (2 * i - 1); j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}
	
	@Test
	public void test4() {
		// 计算1-100以内所有奇数的和以及所有偶数的和，分别打印出来
		int oddSum = 0;
		int evenSum = 0;
		for (int i = 0; i <= 100; i++) {
			if (i % 2 == 0) {
				evenSum += i;
			} else {
				oddSum += i;
			}
		}
		System.out.println("奇数和：" + oddSum);
		System.out.println("偶数和：" + evenSum);
	}
	
	@Test
	public void hw4() {
		int count = 0;
		for (int i = 1; i <= 1000; i++) {
			if (i % 5 == 0) {
				System.out.print(i + " ");
				count++;
//				if(count == 3){
//					System.out.println();
//					count = 0;
//				}
				
				// 0%3取余 商是0 余数0
				if (count % 3 == 0) {
					System.out.println();
				}
			}
		}
	}
	
	@Test
	public void test66() {
		for (int i = 1; i <= 10; i++) {
			System.out.println(i);
		}
	}
	
	// 计算9的阶乘
	@Test
	public void test15() {
		int factorial = 1;
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入要求的阶乘的数");
		int num = scanner.nextInt();
		// 4!=4*3*2*1
		for (int i = 1; i <= num; i++) {
			factorial = factorial * i;
		}
		System.out.println(factorial);
	}
	
	@Test
	public void test16() {
		int factorial = 1;
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入要求的阶乘的数");
		int num = scanner.nextInt();
		// 4!=4*3*2*1
		for (int i = num; i >= 1; i--) {
			factorial = factorial * i;
		}
		System.out.println(factorial);
	}

	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入利润：");
		double lirun = scanner.nextDouble();
		double jiangJin = 0;
		if (lirun > 0 && lirun <= 10) {
			jiangJin = lirun * 0.1;
		} else if (lirun > 10 && lirun <= 20) {
			jiangJin = 10 * 0.1 + (lirun - 10) * 0.075;
		} else if (lirun > 20 && lirun <= 40) {
			jiangJin = 10 * 0.1 + 10 * 0.075 + (lirun - 20) * 0.05;
		}
		
		System.out.println(jiangJin);
	}
	
	// 使用循环打印100-200之间所有的素数
	@Test
	public void test7() {
		for (int i = 100; i <= 200; i++) {
			boolean isSuShu = true;
			// 初始认为是素数
			for (int j = 2; j < i; j++) {
				if (i % j == 0) {// 不是素数
					isSuShu = false;
					break;// 只要找到一个就可以
				}
			}
			if (isSuShu == true) {
				System.out.println(i + "是素数");
			}
		}
	}
}
